﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace SECSendMsgService
{
   public class XMLHelper
    {
       /// <summary>
       /// 初始化根节点对象
       /// </summary>
       XmlDocument doc = new XmlDocument();
       /// <summary>
       /// 加载xml文件
       /// </summary>
       /// <param name="path"></param>
       public XMLHelper(string path)
       {
           //
           // TODO: 在此处添加构造函数逻辑
           //			
           if (System.IO.File.Exists(path))
               doc.Load(path);
       }
      /// <summary>
       /// 得到单个节点的InnerText
      /// </summary>
      /// <param name="nodeName">节点名字</param>
      /// <returns></returns>>
       public string GetSingleInnerTextByNodeName(string nodeName)
       {
           return doc.SelectSingleNode(nodeName).InnerText;
       }
       /// <summary>
       /// 得到想同节点名的Text的集合
       /// </summary>
       /// <param name="nodeName">节点名字</param>
       /// <returns></returns>
       public List<string>  GetListByNodeName(string nodeName)
       {
           List<string> list = new List<string>();
           XmlNodeList nodes = doc.SelectNodes(nodeName); //得到节点的集合
           foreach (XmlNode item in nodes)
           {
               list.Add(item.InnerText);
           }
           return list;
       }
    }
}
